import React, { Component } from 'react';
import router from 'umi/router';

class Notice extends Component {
  // 立即办理
  startHandle = () => {
    const {
      dispatch,
      location,
      data: { sysMsgId, vno },
    } = this.props;
    const { pathname } = location;
    dispatch({
      type: 'global/fetchMsgUrl',
      payload: { sysMsgId },
      callback: response => {
        if (response.data) {
          dispatch({
            type: 'global/changeNoticeReadState',
            payload: { sysMsgId, vno },
          });
          if (response.data.msgUrl === pathname) {
            router.go(0);
          }
          if (response.data.reqParamType === 1) {
            // 详情
            router.push(response.data.msgUrl);
          } else {
            // 列表
            const routerParams = {
              pathname: response.data.msgUrl,
              queryParam: JSON.parse(response.data.dataParam),
              query: {
                isMenuLink: false,
                activeKey: response.data.dataParam.curStep,
              },
            };
            router.push(routerParams);
          }
        }
      },
    });
  };

  render() {
    return <a onClick={this.startHandle}>立即办理</a>;
  }
}

export default Notice;
